package com.example.test_witns.ui.Library;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.NavOptions;
import androidx.navigation.fragment.NavHostFragment;

import com.example.test_witns.R;
import com.example.test_witns.databinding.FragmentLibraryBinding;


public class LibraryFragment extends Fragment {
    FragmentLibraryBinding binding;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentLibraryBinding.inflate(inflater, container,false);
        View root = binding.getRoot();

        Window window = getActivity().getWindow();
        window.setStatusBarColor(Color.parseColor("#eeeeee"));
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

        NavOptions navOptions = new NavOptions.Builder()
                .setLaunchSingleTop(false) // 确保如果目标 Fragment 已经在顶部，不会创建新的实例
                .setPopUpTo(R.id.navigation_home, true) // 设置为 true 将移除直到起始目的地的所有 Fragment
                .setRestoreState(false) // 不恢复状态，通常与 setPopUpTo 结合使用
                .build();

        NavController navController = NavHostFragment.findNavController(this);

        TextView textView_todo = root.findViewById(R.id.Home_TODO);
        textView_todo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navController.navigate(R.id.action_navigation_analysis_to_navigation_todo,null, navOptions);

            }
        });

        TextView textView_recommendation = root.findViewById(R.id.Home_recommendation);
        textView_recommendation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navController.navigate(R.id.action_navigation_analysis_to_navigation_home,null, navOptions);
            }
        });

        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}
